package com.example.common;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

public class CheckConnection {
	private Context mContext;

	public CheckConnection(Context ctx) {
		mContext = ctx;
	}

	public boolean isConnected() {
		ConnectivityManager connectivityManager = (ConnectivityManager) mContext
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivityManager != null) {
			NetworkInfo mobileNetwork = connectivityManager
					.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
			NetworkInfo wifiNetwork = connectivityManager
					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			if (wifiNetwork != null) {
				if (wifiNetwork.isConnected()) {
					Toast.makeText(mContext, "Connected by Wifi", 2000).show();
					return true;
					
				}
			}
			if (mobileNetwork != null) {
				if (mobileNetwork.isConnected()) {
					Toast.makeText(mContext, "Connected by 3G", 2000).show();
					return true;
				}
			}
		}
		return false;
	}
}
